<?php

namespace App\Http\Controllers\Common;

use App\Model\Common\Slider;
use App\Model\Common\User;
use Illuminate\Http\Request;

class UserController extends CommonController
{
    public function index()
    {
    }

    public function profile()
    {
    }

    public function login()
    {
        $sliders = Slider::getSliders('login');
        $this->assign('sliders', $sliders);
        $this->assignSiteInfo('user/login');

        return $this->fetch();
    }

    public function logout(Request $request)
    {
        User::logoutTheUser();
        if ($request->ajax() || (isset($_REQUEST['_async']) && 1 == $_REQUEST['_async'])) {
            return output(0, '', ['redirect' => route('home')]);
        } else {
            return redirect()->route('home');
        }
    }

    public function register(Request $request)
    {
        $sliders = Slider::getSliders('register');
        $this->assign('sliders', $sliders);
        $this->assignSiteInfo('user/register');

        if ($request->has('token') && $request->has('email')) {
            $email = $request->input('email');
            if (is_email($email)) {
                $this->assign('is_do', 1);
                $this->assign('token', $request->input('token'));
                $this->assign('email', $email);
            } else
            {
                $this->assign('is_do', 0);
            }
        } else {
            $this->assign('is_do', 0);
        }

        return $this->fetch();
    }

    public function findPwd()
    {
    }

    public function oldEmailVerify()
    {
    }

    public function newEmailVerify()
    {
    }

    public function changePwd()
    {
    }
}
